package Presentacion;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import javax.swing.ButtonGroup;

import Dominio.AgenteTest;
import Dominio.Test;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class realizarTest {

	private JFrame frmRealizarTest;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private final ButtonGroup buttonGroup_1 = new ButtonGroup();
	private final ButtonGroup buttonGroup_2 = new ButtonGroup();
	private final ButtonGroup buttonGroup_3 = new ButtonGroup();
	private final ButtonGroup buttonGroup_4 = new ButtonGroup();
	private final ButtonGroup buttonGroup_5 = new ButtonGroup();
	private final ButtonGroup buttonGroup_6 = new ButtonGroup();
	private final ButtonGroup buttonGroup_7 = new ButtonGroup();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					realizarTest window = new realizarTest();
					window.frmRealizarTest.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public realizarTest() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmRealizarTest = new JFrame();
		frmRealizarTest.setTitle("Realizar Test");
		frmRealizarTest.setBounds(100, 100, 489, 423);
		frmRealizarTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmRealizarTest.getContentPane().setLayout(null);
		
		JLabel lblteGusta = new JLabel("1. ¿Te gusta el cine de terror?");
		lblteGusta.setBounds(10, 11, 204, 14);
		frmRealizarTest.getContentPane().add(lblteGusta);
		
		JLabel lblsuelesAcudir = new JLabel("2. ¿Sueles acudir a conciertos?");
		lblsuelesAcudir.setBounds(10, 54, 200, 14);
		frmRealizarTest.getContentPane().add(lblsuelesAcudir);
		
		JLabel lblhablasIngls = new JLabel("3. ¿Hablas inglés a un nivel fluido?");
		lblhablasIngls.setBounds(10, 98, 200, 14);
		frmRealizarTest.getContentPane().add(lblhablasIngls);
		
		JLabel lbleresFan = new JLabel("4. ¿Eres fan de algun deporte de pelota?");
		lbleresFan.setBounds(10, 143, 233, 14);
		frmRealizarTest.getContentPane().add(lbleresFan);
		
		JLabel lbljuegasNormalmente = new JLabel("5. ¿Juegas normalmente a videojuegos?");
		lbljuegasNormalmente.setBounds(10, 186, 233, 14);
		frmRealizarTest.getContentPane().add(lbljuegasNormalmente);
		
		JLabel lblleesNovelas = new JLabel("6. ¿Lees novelas con una frecuencia alta?");
		lblleesNovelas.setBounds(10, 231, 253, 14);
		frmRealizarTest.getContentPane().add(lblleesNovelas);
		
		JLabel lblutilizasAplicaciones = new JLabel("7. ¿Utilizas aplicaciones móviles mas de 5 horas diarias?");
		lblutilizasAplicaciones.setBounds(10, 274, 332, 14);
		frmRealizarTest.getContentPane().add(lblutilizasAplicaciones);
		
		JLabel lblteGusta_1 = new JLabel("8. ¿Te gusta la playa más que la montaña?");
		lblteGusta_1.setBounds(10, 313, 253, 14);
		frmRealizarTest.getContentPane().add(lblteGusta_1);
		
		final JRadioButton rdbtnS1 = new JRadioButton("Sí");
		buttonGroup.add(rdbtnS1);
		rdbtnS1.setBounds(216, 7, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnS1);
		
		final JRadioButton rdbtnN1 = new JRadioButton("No");
		buttonGroup.add(rdbtnN1);
		rdbtnN1.setBounds(278, 7, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnN1);
		
		final JRadioButton rdbtnS2 = new JRadioButton("Sí");
		buttonGroup_1.add(rdbtnS2);
		rdbtnS2.setBounds(216, 50, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnS2);
		
		final JRadioButton rdbtnS3 = new JRadioButton("Sí");
		buttonGroup_2.add(rdbtnS3);
		rdbtnS3.setBounds(216, 94, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnS3);
		
		final JRadioButton rdbtnS4 = new JRadioButton("Sí");
		buttonGroup_3.add(rdbtnS4);
		rdbtnS4.setBounds(249, 139, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnS4);
		
		final JRadioButton rdbtnS5 = new JRadioButton("Sí");
		buttonGroup_4.add(rdbtnS5);
		rdbtnS5.setBounds(249, 182, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnS5);
		
		final JRadioButton rdbtnS6 = new JRadioButton("Sí");
		buttonGroup_5.add(rdbtnS6);
		rdbtnS6.setBounds(263, 227, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnS6);
		
		final JRadioButton rdbtnS7 = new JRadioButton("Sí");
		buttonGroup_6.add(rdbtnS7);
		rdbtnS7.setBounds(352, 270, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnS7);
		
		final JRadioButton rdbtnS8 = new JRadioButton("Sí");
		buttonGroup_7.add(rdbtnS8);
		rdbtnS8.setBounds(263, 309, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnS8);
		
		final JRadioButton rdbtnN2 = new JRadioButton("No");
		buttonGroup_1.add(rdbtnN2);
		rdbtnN2.setBounds(278, 50, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnN2);
		
		final JRadioButton rdbtnN3 = new JRadioButton("No");
		buttonGroup_2.add(rdbtnN3);
		rdbtnN3.setBounds(278, 94, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnN3);
		
		final JRadioButton rdbtnN4 = new JRadioButton("No");
		buttonGroup_3.add(rdbtnN4);
		rdbtnN4.setBounds(298, 139, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnN4);
		
		final JRadioButton rdbtnN5 = new JRadioButton("No");
		buttonGroup_4.add(rdbtnN5);
		rdbtnN5.setBounds(298, 182, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnN5);
		
		final JRadioButton rdbtnN6 = new JRadioButton("No");
		buttonGroup_5.add(rdbtnN6);
		rdbtnN6.setBounds(312, 227, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnN6);
		
		final JRadioButton rdbtnN7 = new JRadioButton("No");
		buttonGroup_6.add(rdbtnN7);
		rdbtnN7.setBounds(401, 270, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnN7);
		
		final JRadioButton rdbtnN8 = new JRadioButton("No");
		buttonGroup_7.add(rdbtnN8);
		rdbtnN8.setBounds(312, 309, 47, 23);
		frmRealizarTest.getContentPane().add(rdbtnN8);
		
		JButton btnEnviarTest = new JButton("Enviar Test");
		btnEnviarTest.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				int p1=2, p2=2, p3=2, p4=2, p5=2, p6=2, p7=2 ,p8= 2;
				boolean completo= true;
				
				if(rdbtnS1.isSelected()){
					p1=0;
				}else if(rdbtnN1.isSelected()){
					p1=1;
				}else{
					completo= false;
				}
				
				if(rdbtnS2.isSelected()){
					p2=0;
				}else if(rdbtnN2.isSelected()){
					p2=1;
				}else{
					completo= false;
				}
				
				if(rdbtnS3.isSelected()){
					p3=0;
				}else if(rdbtnN3.isSelected()){
					p3=1;
				}else{
					completo= false;
				}
				
				if(rdbtnS4.isSelected()){
					p4=0;
				}else if(rdbtnN4.isSelected()){
					p4=1;
				}else{
					completo= false;
				}
				
				if(rdbtnS5.isSelected()){
					p5=0;
				}else if(rdbtnN5.isSelected()){
					p5=1;
				}else{
					completo= false;
				}
				
				if(rdbtnS6.isSelected()){
					p6=0;
				}else if(rdbtnN6.isSelected()){
					p6=1;
				}else{
					completo= false;
				}
				
				if(rdbtnS7.isSelected()){
					p7=0;
				}else if(rdbtnN7.isSelected()){
					p7=1;
				}else{
					completo= false;
				}
				
				if(rdbtnS8.isSelected()){
					p8=0;
				}else if(rdbtnN8.isSelected()){
					p8=1;
				}else{
					completo= false;
				}
				
				
				boolean realizado= false;
				if(completo){
					Test test= new Test(MenuPrincipal.DNI, p1, p2, p3, p4, p5, p6, p7, p8);
					AgenteTest agenttest= new AgenteTest();
					
					realizado= agenttest.insertarTest(test);
					
					if(realizado)
						JOptionPane.showMessageDialog(null, "Test Enviado");
		            else
		            	JOptionPane.showMessageDialog(null, "Error al Enviar Test");
		            
					frmRealizarTest.setVisible(false);
					
				}else
					JOptionPane.showMessageDialog(null, "Debes contestar a todas las preguntas");
			}
		});
		btnEnviarTest.setBounds(177, 351, 118, 23);
		frmRealizarTest.getContentPane().add(btnEnviarTest);
	}

}
